#include "server.h"

int thrd_worker(struct worker_ctl *worker_ctl)
{/*{{{*/
#define _TIMEOUT_MS     (10*1000)
    extern int svc_call(char *peer_ip, char *msg_in);
    char *msg_in=worker_ctl->msg_in;
    int msg_in_size;
    struct sockd_addr peer_addr;
    char peer_ip[IP_SIZE+1];
    int timeout_ms;
    int res;

    while(1)
    {
        timeout_ms=_TIMEOUT_MS;
        if((res=sockd_recvfrom(worker_ctl->sock, &peer_addr,
                        (unsigned char *)msg_in, &msg_in_size,
                        &timeout_ms)))
        {
            if(res != RET_ERR_TIMEOUT)
            {
                errlog("%s: sockd_recvfrom fail, res:%d",
                        __func__, res);
            }
            continue;
        }

        inet_ntop(AF_INET, &peer_addr.ip, peer_ip, sizeof(peer_ip));
        msg_in[msg_in_size]=ZERO;
        if((res=svc_call(peer_ip, msg_in)))
        {
            errlog("%s %s: svc_call res(%d), from(%s)",
                    __FILE__, __func__, res, peer_ip);
        }
    }

    return(0);
}/*}}}*/
